extends ../layout

block content
	div.row
		div.panel.panel-primary
			div.panel-heading
				strong 博客编辑
			div.panel-body
				input(type='text',name='id',value='#{blog?blog._id:"null"}').display#blogId
				section.panel
					div.input-group
						span.input-group-addon 标题
						input(type='text', name='title', value='#{blog ? blog.title:""}').form-control#blogTitle
				section.panel
					-var currentCategory='';
					div.input-group
						span(type='button', data-toggle='dropdown').input-group-addon.dropdown-toggle.pointer 类别
							span.caret
						ul(role='menu').dropdown-menu#categoryList
							each category in categories
								li(_id='#{category._id}')
									a #{category.name}
						input(type='text', name='category',value='#{blog?blog.category._id:""}').display#categoryId
						input(type='text', disabled='disabled', value='#{blog?blog.category.name:""}').form-control#categoryName

				section.panel
					script(type="text/plain",id="myEditor",name="content")
				p.text-left
					small.red#blogError
				section.panel
					input(type='button', value='保存').btn.btn-primary#blogSubmit

block scripts
	script(src='/ueditor/ueditor.config.js')
	script(src='/ueditor/editor_api.js')
	script(type='text/javascript', src='/javascripts/blog.js')
	if (blog)
		script(type='text/javascript').
			ue = UE.getEditor('myEditor',{initialFrameHeight:500});
			ue.ready(function() {
				$.ajax({
					url: '/blogs/#{blog._id}/content',
					type: 'GET',
					success: function(result) {
						ue.setContent(result);
					}
				});
			});
	else
		script(type='text/javascript').
			ue = UE.getEditor('myEditor',{initialFrameHeight:500});